package com.briup.mt.service.impl;

import com.briup.mt.bean.Application;
import com.briup.mt.bean.ApplicationExample;
import com.briup.mt.dao.ApplicationMapper;
import com.briup.mt.service.IApplicationService;
import com.briup.mt.utils.Message;
import com.briup.mt.utils.MessageUtil;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
@Service
public class ApplicationServiceImpl implements IApplicationService {
   @Resource
   private ApplicationMapper applicationMapper;
    @Override
    public List<Application> query(String name) {
       ApplicationExample applicationExample=new ApplicationExample();
        if(StringUtils.hasLength(name))
           applicationExample.createCriteria().andNameLike("%"+name+"%");
        return applicationMapper.selectByExample(applicationExample);
    }

    @Override
    public void saveOrUpdate(Application application) {
        if (application.getId()==null){
            application.setCreateTime(new Date().getTime());
            applicationMapper.insert(application);
        }
      else {
          applicationMapper.updateByPrimaryKey(application);
        }
    }

    @Override
    public void deleteById(Long id) {
        applicationMapper.deleteByPrimaryKey(id);
    }


}